package com.simple.javatraining.testing.questionsformer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.simple.javatraining.testing.testinside.answers.ProposedAnswer;
import com.simple.javatraining.testing.testinside.questions.*;

public class HardcodedQuestionsFormer {

private static HardcodedQuestionsFormer hardcodedQuestions;
private List<Question> listOfQuestions = new ArrayList<Question>();

private HardcodedQuestionsFormer() {
    List<ProposedAnswer> listOfAnswers_1 = new LinkedList<ProposedAnswer>();
    listOfAnswers_1.add(new ProposedAnswer("8", true));
	listOfQuestions.add(new QuestionWithAnswerWithinRange(
		        "Сколько примитивных типов данных существует в языке программирования Java?",
		            listOfAnswers_1, 2d));

    List<ProposedAnswer> listOfAnswers_2 = new LinkedList<ProposedAnswer>();
    listOfAnswers_2.add(new ProposedAnswer("Арифметические операции над целыми "
            +"числами могут приводить к ошибкам переполнения", true));
    listOfAnswers_2.add(new ProposedAnswer("Не существует автоматического "
                    +"преобразования типов к типу boolean", true));
    listOfAnswers_2.add(new ProposedAnswer("Сравнение с константой NaN всегда дает истинный результат", false));
    listOfAnswers_2.add(new ProposedAnswer("Сравнение 2-х чисел с плавающей точкой, "
                    +"как правило, дает истинный результат", false));
	listOfQuestions.add(new QuestionWithSeveralAnswers(
		        "Выберите правильные утверждения:",
                    listOfAnswers_2));

    List<ProposedAnswer> listOfAnswers_3 = new LinkedList<ProposedAnswer>();
    listOfAnswers_3.add(new ProposedAnswer("symbol = 's';", true));
    listOfAnswers_3.add(new ProposedAnswer("symbol = s;", false));
    listOfAnswers_3.add(new ProposedAnswer("symbol = “s”;", false));
    listOfAnswers_3.add(new ProposedAnswer("symbol = [s];", false));
	 listOfQuestions.add(new QuestionWithSingleAnswer(
		        "Обьявлена переменная symbol символьного типа. "
		       +"Какая из приведенных строчек инициализации является корректной?",
		            listOfAnswers_3));

    List<ProposedAnswer> listOfAnswers_4 = new LinkedList<ProposedAnswer>();
    listOfAnswers_4.add(new ProposedAnswer("Ошибка компиляции", true));
    listOfAnswers_4.add(new ProposedAnswer("В консоль выведется 1", false));
    listOfAnswers_4.add(new ProposedAnswer("В консоль выведется 2", false));
	listOfQuestions.add(new QuestionWithSingleAnswer(
		        "Какой результат выполнения кода:\n\n"
		       +"public class Test {\n"
		       +"    public static boolean returnResult (int x) {\n"
		       +"        return (x <= Int.POSITIVE_INFINITY);\n"
		       +"    }\n" + "    public static void main (String args[]) {\n"
		       +"        final int value = 5;\n"
		       +"        if (returnResult(value)) {\n"
		       +"            System.out.println(“1”);\n"
		       +"        } else {\n"
		       +"               System.out.println(“2”);\n"
		       +"               }\n" + "    }\n}",
		            listOfAnswers_4));

    List<ProposedAnswer> listOfAnswers_5 = new LinkedList<ProposedAnswer>();
    listOfAnswers_5.add(new ProposedAnswer("0", true));
    listOfAnswers_5.add(new ProposedAnswer("1", false));
    listOfAnswers_5.add(new ProposedAnswer("26", false));
    listOfAnswers_5.add(new ProposedAnswer("5", false));
	listOfQuestions.add(new QuestionWithSingleAnswer(
		        "Какой результат выполнения кода:\n\n"
		       +"public class Test2 {\n"
		       +"    public static void main (String args[]) {\n"
		       +"        int x = 25;\n        int y = 5;\n"
		       +"        System.out.println((y / x / y  + (y / x) * 4 * x + x - 1) / x );\n"
		       +"    }\n" + "}",
		            listOfAnswers_5));

    List<ProposedAnswer> listOfAnswers_6 = new LinkedList<ProposedAnswer>();
    listOfAnswers_6.add(new ProposedAnswer("String symbol = “/*символ*/“ ", true));
    listOfAnswers_6.add(new ProposedAnswer("char symbol = '/*символ*/'", false));
	listOfQuestions.add(new QuestionWithSingleAnswer(
		        "Какая запись более корректна в случае символа кодировки UTF-16:",
		            listOfAnswers_6));

    List<ProposedAnswer> listOfAnswers_7 = new LinkedList<ProposedAnswer>();
    listOfAnswers_7.add(new ProposedAnswer("3TestTest12", true));
	listOfQuestions.add(new QuestionWithEnterableAnswer(
		        "Какой результат выполнения следующего кода:\n\n"
		       +"public class Test3 {\n"
		       +"    public static void main (String args[]) {\n"
		       +"        System.out.println((1+2+”Test”) + (”Test”+1+2));"
		       +"    }\n}",
		            listOfAnswers_7));

    List<ProposedAnswer> listOfAnswers_8 = new LinkedList<ProposedAnswer>();
    listOfAnswers_8.add(new ProposedAnswer("true", true));
    listOfAnswers_8.add(new ProposedAnswer("false", false));
    listOfAnswers_8.add(new ProposedAnswer("Ошибка компиляции", false));
	listOfQuestions.add(new QuestionWithSingleAnswer(
		        "Какой результат выполнения следующего кода:\n\n"
		       +"public class Test4 {\n"
		       +"    public static void main (String args[]) {\n"
		       +"        int x = 6;"
		       +"        System.out.println( ( (float)x <Float.POSITIVE_INFINITY) && (0.0 == -0.0) );"
		       +"    }\n}",
		            listOfAnswers_8));
	List<ProposedAnswer> listOfAnswers_9 = new LinkedList<ProposedAnswer>();
    listOfAnswers_9.add(new ProposedAnswer("no", true));
    listOfAnswers_9.add(new ProposedAnswer("yes", false));
	listOfQuestions.add(new QuestionWithYesNoAnswer(
		        "Используется ли тип данных с плавающей точкой для денежных операций?",
		            listOfAnswers_9));

    List<ProposedAnswer> listOfAnswers_10 = new LinkedList<ProposedAnswer>();
    listOfAnswers_10.add(new ProposedAnswer("true \n   0.2 \n   0.20000000298023224", false));
    listOfAnswers_10.add(new ProposedAnswer("false \n   0.2 \n   0.20000000298023224", false));
    listOfAnswers_10.add(new ProposedAnswer("true \n   0.2 \n   0.2", false));
    listOfAnswers_10.add(new ProposedAnswer("false \n   0.2 \n   0.2", true));
	 listOfQuestions.add(new QuestionWithSingleAnswer(
		        "Какой результат выполнения следующего кода:\n\n"
		       +"public class Test5 {\n"
		       +"    public static void main (String args[]) {\n"
		       +"        int x = 2;\n"
		       +"        double y =(double) x / 10;\n"
		       +"        float z =(float) x / 10;\n"
		       +"        System.out.println(y == z);\n"
		       +"        System.out.println(y);\n"
		       +"        System.out.println(z);\n"
		       +"    }\n}",
		            listOfAnswers_10));
}

public static HardcodedQuestionsFormer getHardcodedQuestions() {
	if(hardcodedQuestions == null) {
		hardcodedQuestions = new HardcodedQuestionsFormer();
	}
	return hardcodedQuestions;
}

public List<Question> getAllQuestions() {
    List<Question> allQuestions = new ArrayList<Question>(this.listOfQuestions);
    return allQuestions;
}

public int getNumberOfQuestions() {
    return this.listOfQuestions.size();
}

public int getIndexOfQuestion(Question question) {
    return this.listOfQuestions.indexOf(question);
}
}
